﻿using Demo.Net.EFCore;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Npgsql;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;

namespace Microsoft.Extensions.DependencyInjection
{
    public static class EFCoreDBComExtensions
    {


        public static IServiceCollection AddEFCoreExtensions(this IServiceCollection services, IConfiguration configuration)
        {
            services.AddDbContext<EFCoreDBContext>(options =>
            {
                var builder = new NpgsqlConnectionStringBuilder(configuration["PgSqlConnectionString"]);
                builder.CommandTimeout = 120;
                options.UseNpgsql(builder.ConnectionString);
           
                switch (Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT"))
                {
                    case "Development":
                    case "Staging":
                        {
                          options.LogTo(Console.WriteLine, LogLevel.Information);
                            break;
                        }
                    case "Production": break;
                }
            });


            
            return services;
        }
    }
}
